package main

import "fmt"

var arr [7]int = [7]int{1, 2, 3, 4, 5, 6, 7}

func main() {
	sliceAppend()
	fmt.Println("-----------------")
	sliceCopy()
	fmt.Println("-----------------")
	str()
}

func sliceAppend() {
	a := arr[0:2] //左闭右开
	a = append(a, 1)
	fmt.Println(a)
	b := make([]int, 0, 5)
	b = append(b, 11)

	a = append(a, b...) //利用...语法糖 把切片展开
	fmt.Println(b)
	fmt.Println(a)
}

func sliceCopy() {
	a := arr[:]
	b := make([]int, 5, 10)
	copy(b, a)
	fmt.Println(arr)
	fmt.Println(b)
	// [1 2 1 11 5]

	d := make([]int, 10, 10)
	copy(d, a)
	fmt.Println(d)
	// [1 2 1 11 5 6 7 0 0 0]
}

func str() {
	str := "hello world"
	a := []byte(str)
	fmt.Println(a)
}
